package com.software.demo4.test;

import com.software.demo4.entity.User;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class Run {
    public static void main(String[] args) {
        Configuration cfg = new Configuration();
        cfg.configure();

        SessionFactory sessionFactory = cfg.buildSessionFactory();
        Session session = sessionFactory.openSession();

        Transaction transaction = session.beginTransaction();
        //业务逻辑
        // 通过主键查询数据
        User user = session.get(
                User.class,
                "b1487069-0272-4a5d-9c00-2484ca08b761"
        );
        System.out.println("=============" + user);

        transaction.commit();
        session.close();
        sessionFactory.close();
    }
}
